<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Supervisor使用详解 | Abel&#39;Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="简介supervisor是用Python开发的一个client&#x2F;server服务，是Linux&#x2F;Unix系统下的一个进程管理工具。可以很方便的监听、启动、停止、重启一个或多个进程。用supervisor管理的进程，当一个进程意外被杀死，supervisor监听到进程死后，会自动将它重启，很方便的做到进程自动恢复的功能，不再需要自己写shell脚本来控制。 安装1234# ubuntu安装：sudo">
<meta property="og:type" content="article">
<meta property="og:title" content="Supervisor使用详解">
<meta property="og:url" content="http://example.com/2021/07/28/2020/2020-11-16-supervisor/index.html">
<meta property="og:site_name" content="Abel&#39;Blog">
<meta property="og:description" content="简介supervisor是用Python开发的一个client&#x2F;server服务，是Linux&#x2F;Unix系统下的一个进程管理工具。可以很方便的监听、启动、停止、重启一个或多个进程。用supervisor管理的进程，当一个进程意外被杀死，supervisor监听到进程死后，会自动将它重启，很方便的做到进程自动恢复的功能，不再需要自己写shell脚本来控制。 安装1234# ubuntu安装：sudo">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://s3.ax1x.com/2020/11/16/DAtsTe.png">
<meta property="article:published_time" content="2021-07-28T03:33:01.207Z">
<meta property="article:modified_time" content="2021-06-23T01:38:03.331Z">
<meta property="article:author" content="Abel Sean">
<meta property="article:tag" content="运维">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s3.ax1x.com/2020/11/16/DAtsTe.png">
  
    <link rel="alternate" href="/atom.xml" title="Abel&#39;Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Abel&#39;Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-2020/2020-11-16-supervisor" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/07/28/2020/2020-11-16-supervisor/" class="article-date">
  <time datetime="2021-07-28T03:33:01.207Z" itemprop="datePublished">2021-07-28</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Supervisor使用详解
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p>supervisor是用Python开发的一个client/server服务，是Linux/Unix系统下的一个进程管理工具。可以很方便的监听、启动、停止、重启一个或多个进程。用supervisor管理的进程，当一个进程意外被杀死，supervisor监听到进程死后，会自动将它重启，很方便的做到进程自动恢复的功能，不再需要自己写shell脚本来控制。</p>
<h1 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ubuntu安装：</span></span><br><span class="line">sudo apt-get install supervisor</span><br><span class="line"><span class="comment"># centos安装</span></span><br><span class="line">yum install -y supervisor</span><br></pre></td></tr></table></figure>

<p>检查是否一个守护进程</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@test-qingzhou-01 supervisord.d]<span class="comment"># ps aux |grep supervisord</span></span><br><span class="line">root      4154  0.0  0.1  56144 15060 pts/0    Ss+  13:31   0:00 /usr/bin/python /usr/bin/supervisord -nc /etc/supervisor/supervisord.conf</span><br><span class="line"><span class="comment"># 手动启动方式</span></span><br><span class="line">supervisord -c /etc/supervisor/supervisord.conf</span><br><span class="line"><span class="comment"># 手动关闭</span></span><br><span class="line">ps aux |grep -v grep | grep supervisord | awk <span class="string">&#x27;&#123;print $2&#125;&#x27;</span> |xargs <span class="built_in">kill</span> -2</span><br></pre></td></tr></table></figure>

<h1 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h1><p>系统配置位置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">/etc/supervisor/supervisord.conf</span><br><span class="line"></span><br><span class="line">开启一个http的服务，方便外部访问：</span><br><span class="line">[inet_http_server]         ; inet (TCP) server disabled by default</span><br><span class="line"> port=0.0.0.0:10080        ; (ip_address:port specifier, *:port <span class="keyword">for</span> all iface)                                                  </span><br><span class="line"> username=user              ; (default is no username (open server))</span><br><span class="line"> password=123               ; (default is no password (open server))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改默认进程数字：</span></span><br><span class="line">minfds=65535                ; (min. avail startup file descriptors;default 1024)</span><br><span class="line">minprocs=65535              ; (min. avail process descriptors;default 200)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>配置自己的ini</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="section">[group:qzsrv3]</span></span><br><span class="line"><span class="attr">programs</span>=Lobby,Gateway,Scene,Matcher,Level,DBServer</span><br><span class="line"></span><br><span class="line"><span class="section">[program:Login]</span></span><br><span class="line"><span class="attr">directory</span>=/home/teamcityagent/BuildAgent/work/<span class="number">5</span>c951883da1eba28/server/bin</span><br><span class="line"><span class="attr">command</span>=/home/teamcityagent/BuildAgent/work/<span class="number">5</span>c951883da1eba28/server/bin/Login srv3</span><br><span class="line"><span class="attr">autostart</span>=<span class="literal">false</span></span><br><span class="line"><span class="attr">autorestart</span>=unexpected</span><br><span class="line"><span class="attr">startsecs</span>=<span class="number">1</span></span><br><span class="line"><span class="attr">stderr_logfile</span>=/home/teamcityagent/BuildAgent/work/<span class="number">5</span>c951883da1eba28/server/log/Login.err.log</span><br><span class="line"><span class="attr">stdout_logfile</span>=/home/teamcityagent/BuildAgent/work/<span class="number">5</span>c951883da1eba28/server/log/Login.log</span><br><span class="line"><span class="attr">user</span>=teamcityagent</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这里可以指定是否出现问题之后直接重启。</p>
<h1 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@test-qingzhou-01 supervisor]<span class="comment"># /usr/local/bin/supervisord -c ./supervisrd.conf </span></span><br><span class="line">Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.</span><br><span class="line"></span><br><span class="line">[root@test-qingzhou-01 supervisor]<span class="comment"># find / -name supervisor.sock</span></span><br><span class="line">/run/supervisor/supervisor.sock</span><br><span class="line">/var/lib/docker/overlay2/d6de9ac36e7b3c66fed11ddb3cf384a18932d3f8044dda5bb2247476604acd71/diff/run/supervisor.sock</span><br><span class="line">/var/lib/docker/overlay2/d6de9ac36e7b3c66fed11ddb3cf384a18932d3f8044dda5bb2247476604acd71/merged/run/supervisor.sock</span><br><span class="line">[root@test-qingzhou-01 supervisor]<span class="comment"># unlink /run/supervisor/supervisor.sock</span></span><br><span class="line">[root@test-qingzhou-01 supervisor]<span class="comment"># unlink /var/lib/docker/overlay2/d6de9ac36e7b3c66fed11ddb3cf384a18932d3f8044dda5bb2247476604acd71/diff/run/supervisor.sock</span></span><br><span class="line">[root@test-qingzhou-01 supervisor]<span class="comment"># unlink /var/lib/docker/overlay2/d6de9ac36e7b3c66fed11ddb3cf384a18932d3f8044dda5bb2247476604acd71/merged/run/supervisor.sock</span></span><br><span class="line">unlink: cannot unlink ‘/var/lib/docker/overlay2/d6de9ac36e7b3c66fed11ddb3cf384a18932d3f8044dda5bb2247476604acd71/merged/run/supervisor.sock’: No such file or directory</span><br></pre></td></tr></table></figure>

<h1 id="web"><a href="#web" class="headerlink" title="web"></a>web</h1><p>在后台能直接操作服务器启动</p>
<p><a target="_blank" rel="noopener" href="https://imgchr.com/i/DAtsTe"><img src="https://s3.ax1x.com/2020/11/16/DAtsTe.png" alt="DAtsTe.png"></a></p>
<h1 id="XML-RPC-API"><a href="#XML-RPC-API" class="headerlink" title="XML-RPC API"></a>XML-RPC API</h1><p>可以通过编写python脚本来对web做操作。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> xmlrpc.client <span class="keyword">import</span> ServerProxy</span><br><span class="line"></span><br><span class="line"><span class="comment"># &#x27;http://username:password@localhost:9001/RPC2&#x27;</span></span><br><span class="line">server = ServerProxy(<span class="string">&#x27;http://user:123@172.16.11.92:10080/RPC2&#x27;</span>,verbose=<span class="literal">True</span>)</span><br><span class="line"><span class="comment"># 输出全部的API函数，以xml文件方式输出，可以直接查阅函数，调用就好了。</span></span><br><span class="line"><span class="comment">#print(server.system.listMethods())</span></span><br><span class="line"><span class="comment"># 查看服务器状态</span></span><br><span class="line"><span class="built_in">print</span>(server.supervisor.getState())</span><br><span class="line"><span class="comment"># 关闭全部的服务器</span></span><br><span class="line"><span class="comment">#print(server.supervisor.stopAllProcesses())</span></span><br><span class="line"><span class="comment"># 打开全部的服务器</span></span><br><span class="line"><span class="built_in">print</span>(server.supervisor.startAllProcesses())</span><br></pre></td></tr></table></figure>

<h1 id="supervisord-monitor"><a href="#supervisord-monitor" class="headerlink" title="supervisord-monitor"></a>supervisord-monitor</h1><p><a target="_blank" rel="noopener" href="https://github.com/mlazarov/supervisord-monitor">参考文档-monitor</a></p>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ul>
<li>[1] <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/0b9054b33db3">Supervisor 使用详解</a></li>
<li>[2] <a target="_blank" rel="noopener" href="http://supervisord.org/">Supervisor官网</a></li>
<li>[3] <a target="_blank" rel="noopener" href="https://www.cnblogs.com/zhoujinyi/p/6073705.html">进程管理supervisor的简单说明</a></li>
<li>[4] <a target="_blank" rel="noopener" href="https://blog.csdn.net/zou79189747/article/details/80403016">supervisor 使用详解</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2021/07/28/2020/2020-11-16-supervisor/" data-id="ckrn3an73000r20xw81sf34jx" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%BF%90%E7%BB%B4/" rel="tag">运维</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/07/28/2020/2020-11-18-FSM-Golang/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          FSM-golang
        
      </div>
    </a>
  
  
    <a href="/2021/07/28/2020/2020-11-14-golang-pprof/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">golang-pprof性能分析工具</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/3D/" rel="tag">3D</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AI/" rel="tag">AI</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Game/" rel="tag">Game</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Go/" rel="tag">Go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Math/" rel="tag">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Server/" rel="tag">Server</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Unreal-Engine4/" rel="tag">Unreal Engine4</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/golang/" rel="tag">golang</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/guitar/" rel="tag">guitar</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/node-js/" rel="tag">node.js</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/" rel="tag">protobuf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/recast/" rel="tag">recast</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/type/" rel="tag">type</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vscode/" rel="tag">vscode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BF%90%E7%BB%B4/" rel="tag">运维</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/3D/" style="font-size: 10px;">3D</a> <a href="/tags/AI/" style="font-size: 11.67px;">AI</a> <a href="/tags/C/" style="font-size: 15px;">C++</a> <a href="/tags/Game/" style="font-size: 18.33px;">Game</a> <a href="/tags/Go/" style="font-size: 13.33px;">Go</a> <a href="/tags/Linux/" style="font-size: 13.33px;">Linux</a> <a href="/tags/Math/" style="font-size: 11.67px;">Math</a> <a href="/tags/Server/" style="font-size: 16.67px;">Server</a> <a href="/tags/Unreal-Engine4/" style="font-size: 10px;">Unreal Engine4</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/golang/" style="font-size: 20px;">golang</a> <a href="/tags/guitar/" style="font-size: 10px;">guitar</a> <a href="/tags/node-js/" style="font-size: 10px;">node.js</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/recast/" style="font-size: 11.67px;">recast</a> <a href="/tags/redis/" style="font-size: 10px;">redis</a> <a href="/tags/type/" style="font-size: 10px;">type</a> <a href="/tags/vscode/" style="font-size: 10px;">vscode</a> <a href="/tags/%E8%BF%90%E7%BB%B4/" style="font-size: 16.67px;">运维</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/07/">July 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/07/28/2021/2021-07-19-etcd-learn/">go-etcd阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/07/28/2021/2021-06-22-go-ethereum-learn/">go-ethereum阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/07/28/2021/2021-06-21-server%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7/">server测试工具</a>
          </li>
        
          <li>
            <a href="/2021/07/28/2021/2021-06-09-pprof-doc/">go-pprof</a>
          </li>
        
          <li>
            <a href="/2021/07/28/2021/2021-04-19-c++-metaprogramming/">c++metaprogramming</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Abel Sean<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>